package arrays;

import java.util.Arrays;

/**
 * @author pengfei.hpf
 * @date 2020/3/17
 * @verdion 1.0.0
 */
public class SingleNumber {

    public int singleNumber(int[] nums) {
        if(nums == null || nums.length == 0){
            return 0;
        }
        Arrays.sort(nums);
        int count = 1;
        for(int i = 1; i < nums.length; i++){
            if(nums[i] != nums[i -1]){
                if(count == 1){
                    return nums[i- 1];
                }
                count = 1;
            } else {
                count ++;
            }
        }
        return nums[nums.length - 1];
    }
}
